package com.lh.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lh.commonutils.R;
import com.lh.entity.CrmBanner;
import com.lh.service.ICrmBannerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author lh
 * @since 2021-06-08
 */
@RestController
//@CrossOrigin
@RequestMapping("/educms/bannerAdmin")
public class BannerAdminController {
    @Autowired
    private ICrmBannerService bannerService;

//   分页查询banner

    @ApiOperation(value = "获取Banner分页列表")
    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable long page, @PathVariable long limit){
        Page<CrmBanner> objectPage = new Page<>(page,limit);
        bannerService.page(objectPage,null);
        return  R.ok().data("rows",objectPage.getRecords()).data("total",objectPage.getTotal());
    }

    @ApiOperation(value = "获取Banner")
    @GetMapping("getBanner/{id}")
    public R get(@PathVariable String id) {
        CrmBanner banner = bannerService.getById(id);
        return R.ok().data("item", banner);
    }

    @ApiOperation(value = "新增Banner")
    @PostMapping("addBanner")
    public  R addBanner(@RequestBody CrmBanner crmBanner){
        bannerService.save(crmBanner);
        return R.ok();
    }
    @ApiOperation(value = "修改Banner")
    @PutMapping("updateBanner")
    public R updateById(@RequestBody CrmBanner crmBanner) {
        bannerService.updateById(crmBanner);
        return R.ok();
    }

    @ApiOperation(value = "删除Banner")
    @DeleteMapping("removeBanner/{id}")
    public R remove(@PathVariable String id) {
        bannerService.removeById(id);
        return R.ok();
    }

}

